//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.kingyea.esb.jmx;

import com.kingyea.esb.utils.check.Assert;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.stereotype.Component;

@Component
public class MBeanRegistry implements BeanFactoryAware {
    private Object mbean;
    private String objectName;
    private BeanFactory beanFactory;

    public MBeanRegistry() {
    }

    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = beanFactory;
    }

    public void init() {
        Assert.notNull(this.objectName, "ObjectName不能为空", new Object[0]);
        Assert.notNull(this.mbean, "MBean实例不能为空", new Object[0]);
        Monitor monitor = (Monitor)this.beanFactory.getBean(Monitor.class);
        monitor.registerMBean(this.objectName, this.mbean);
    }

    public void destory() {
        Monitor monitor = (Monitor)this.beanFactory.getBean(Monitor.class);
        monitor.unregisterMBean(this.objectName);
    }

    public Object getMbean() {
        return this.mbean;
    }

    public void setMbean(Object mbean) {
        this.mbean = mbean;
    }

    public String getObjectName() {
        return this.objectName;
    }

    public void setObjectName(String objectName) {
        this.objectName = objectName;
    }
}
